home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / NTUMIN10.ARJ / CHECKOUT.C < prev    next >
C/C++ Source or Header  |  1992-03-12  |  6KB  |  197 lines

  1. /****************************************************************************
  2.  *
  3.  *    Program Name : CHECKOUT.C
  4.  *
  5.  *    Written By : Eng-Huat Ong and Kian-Mong Low.
  6.  *
  7.  *    This program checks the correctness of the solution array by
  8.  *     converting the input array and output array to minterms, sorting
  9.  *    them (ascending order) and check to see if they are equal.
  10.  *
  11.  * --------------------------------------------------------------------------
  12.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  13.  *    University.
  14.  *
  15.  *    You are free to use, copy and distribute this software and its
  16.  *    documentation providing that:
  17.  *
  18.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  19.  *
  20.  *        IT IS NOT MODIFIED IN ANY WAY.
  21.  *
  22.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  23.  *
  24.  *    This program is provided "AS IS" without any warranty, expressed or
  25.  *    implied, including but not limited to fitness for any particular
  26.  *    purpose.
  27.  *
  28.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  29.  *    appreciated. Please send to:
  30.  *
  31.  *        Boon-Tiong Tan or Othman Bin Ahmad
  32.  *        School of EEE
  33.  *        Nanyang Technological University
  34.  *        Nanyang Avenue
  35.  *        Singapore 2263
  36.  *        Republic of Singapore
  37.  *
  38.  ****************************************************************************/
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #define mask8 255
  44.  
  45.  
  46. main()
  47.  
  48. {
  49.    unsigned short    m1, m2, ma, mb, md, i, j, k;
  50.    unsigned char     *infile, *outfile, *readf(), *sorting();
  51.    unsigned char     *a, *b, *d, nspm, na, nb, c;
  52.          int     test;
  53.    unsigned long     m3;
  54.    FILE              *in, *out;            /*  file pointers */
  55.  
  56.    printf("This program is for checking the output generated by the minimization \n");
  57.    printf("program to verify that it is correct.\n\n");
  58.    printf("Before that, the output file must be converted to one similar to the\n");
  59.    printf("input file. (Usable for inputs with DC array)\n\n");
  60.    printf("Press any key to Continue or <ESC> to QUIT\n\n");
  61.    c = getch();
  62.    if (c==27)
  63.       exit(0);
  64.  
  65.    infile = (unsigned char *)malloc (21);       /* space for 1st filename */
  66.    if (infile==0)
  67.       {
  68.      printf("Out of memory -- VERIFY, *infile\n");
  69.      printf("Program Terminated - 1\n");
  70.      exit(0);
  71.       }
  72.  
  73.    outfile = (unsigned char *)malloc (21);      /* space for 2nd filename */
  74.    if (outfile==0)
  75.       {
  76.      printf("Out of memory -- VERIFY, *outfile\n");
  77.      printf("Program Terminated - 2\n");
  78.      exit(0);
  79.       }
  80.  
  81.    printf("Enter input filename -> ");
  82.    gets(infile);                                 /* read 1st filename */
  83.  
  84.    printf("Enter output filename -> ");
  85.    gets(outfile);                                /* read 2nd filename */
  86.  
  87.    if ((in = fopen(infile, "r+")) == NULL)           /* open 1st file */
  88.       {
  89.      printf("Error opening file, %s\n", infile);
  90.      printf("Program terminated.\n ") ;
  91.      exit(0);
  92.       }
  93.  
  94.    if ((out = fopen(outfile, "r+")) == NULL)         /* open 2nd file */
  95.       {
  96.      printf("Error opening file, %s\n", outfile);
  97.      printf("Program terminated.\n ") ;
  98.      exit(0);
  99.       }
  100.  
  101.    d = (unsigned char *) malloc(4);                  /* DC array */
  102.    if (d == 0)
  103.       {
  104.      printf("Out of memory -- VERIFY, *d\n");
  105.      printf("Program terminated.\n ") ;
  106.      exit(0);
  107.       }
  108.  
  109.    /***
  110.     ***  READING FROM FILES AND CONVERTING TO MINTERMS
  111.     ***/
  112.  
  113.    printf("\nPlease Hang On, Reading From Files & Converting To Minterms ... \n\n");
  114.  
  115.    a = readf(in, a, 0);                /* read ON array, 1st file */
  116.    a = sorting(a);                     /* sort in ascending order */
  117.  
  118.    *d = *a;                            /* headers for DC array */
  119.    *(d+1) = 0;
  120.    *(d+2) = 0;
  121.    *(d+3) = *(a+3);
  122.    d = readf(in, d, 1);                /* read DC array */
  123.    d = sorting(d);                     /* sort in ascending order */
  124.    fclose(in);                         /* close 1st file */
  125.  
  126.    na = *a;                            /* no. of variables */
  127.    m1 = *(a+1);
  128.    m2 = *(a+2);
  129.    ma = (m2&mask8)<<8 | m1;            /* no. of minterms */
  130.  
  131.    md = *(d+2)<<8 | *(d+1);
  132.  
  133.    b = readf(out, b, 0);               /* read ON array, 2nd file */
  134.    b = sorting(b);                     /* sort in ascending order */
  135.    fclose(out);                        /* close 2nd file */
  136.  
  137.    nb = *b;                            /* no. of variables */
  138.    m1 = *(b+1);
  139.    m2 = *(b+2);
  140.    nspm = *(b+3);                      /* no. of byte/minterm */
  141.    mb = (m2&mask8)<<8 | m1;            /* no. of minterms */
  142.  
  143.    /***
  144.     ***  COMPARING MINTERMS
  145.     ***/
  146.  
  147.    printf("\nPlease Hang On, Comparing Minterms ... \n\n");
  148.  
  149.    if (na !=  nb)                      /* unequal no. of variables */
  150.       {
  151.      printf("Different number of variables in the 2 files. \n");
  152.      printf("Program Terminated - 3 \n");
  153.      exit(0);
  154.       }
  155.  
  156.    for (i=0; i<mb; i++)           /* minterms in output array */
  157.       {
  158.      for (j=0; j<ma; j++)     /* minterms in ON array */
  159.         {
  160.            test = memcmp((a+4+nspm*j),(b+4+nspm*i),nspm);
  161.            if (test==0)
  162.           {
  163.              ma--;
  164.              memcpy((a+4+nspm*j),(a+4+nspm*(j+1)),nspm*(ma-j));
  165.              break;
  166.           }
  167.         }
  168.  
  169.      if (test!=0)
  170.         {
  171.            for (k=0; k<md; k++)          /* minterms in DC array */
  172.           {
  173.              test = memcmp((d+4+nspm*k),(b+4+nspm*i),nspm);
  174.              if (test==0)
  175.             {
  176.                md--;
  177.                memcpy((d+4+nspm*k),(d+4+nspm*(k+1)),nspm*(md-k));
  178.                break;
  179.             }
  180.           }
  181.         }
  182.      if (test != 0)                          /* not in ON & DC array */
  183.         break;
  184.       }
  185.  
  186.    if (test==0 && ma==0)                         /* successful */
  187.       printf("SUCCESS IN COMPARISION !\n");
  188.    else                                          /* solution array error */
  189.       printf("ERROR IN COMPARISION !\n");
  190.  
  191.    free(a);                          /* free pointers */
  192.    free(b);
  193.    free(d);
  194.    free(infile);
  195.    free(outfile);
  196. }
  197.